package com.dongdong.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdong.pojo.TbContentCategory;
import com.dongdong.service.ContentCategoryService;
import com.dongdongshop.configresult.Result;
import com.dongdongshop.em.ResultEnum;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("contentCategoryController")
public class ContentCategoryController {

    @Reference
    private ContentCategoryService contentCategoryService;

    @RequestMapping("select")
    @ResponseBody
    public Result select(){
        List<TbContentCategory> categoryList = contentCategoryService.selectAll();
        return Result.builResult(ResultEnum.SUCCESS).setResout(categoryList);
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result insert(TbContentCategory tbContentCategory){
        boolean b = contentCategoryService.insert(tbContentCategory);
        if(b){
            return Result.builResult(ResultEnum.SUCCESS);
        }
        return Result.builResult(ResultEnum.ERROR);
    }

    @RequestMapping("deleteId")
    @ResponseBody
    public Result deleteId(Long id){
        boolean b = contentCategoryService.deleteId(id);
        if(b){
            return Result.builResult(ResultEnum.SUCCESS);
        }
        return Result.builResult(ResultEnum.ERROR);
    }

    @RequestMapping("toupdate")
    @ResponseBody
    public Result toupdate(Long id){
            TbContentCategory tbContentCategory = contentCategoryService.selectId(id);
        return Result.builResult(ResultEnum.SUCCESS).setResout(tbContentCategory);
    }

    @RequestMapping("update")
    @ResponseBody
    public Result update(TbContentCategory tbContentCategory){
        boolean b = contentCategoryService.update(tbContentCategory);
        if(b){
            return Result.builResult(ResultEnum.SUCCESS);
        }
        return Result.builResult(ResultEnum.ERROR);
    }
}
